<#import "add_base.ftl" as add/>
<@add.html>
<script type="text/javascript">
  function getme(c) {
    if(c!="") {
      getJson("getEarnest?saleId="+c, function(data){
        if(data.ret) {
          var mc = data.data;
          var fm = getEl("fm_input");
          fm.contractCode.value = mc.saleId;
          fm.saleDate.value = getDateStr(new Date(mc.saleDate));
          fm.earnestType.value = mc.earnestType+" - "+mc.earnestTypeName;
          fm.memberCode.value = mc.memberCode;
          fm.memberName.value = mc.memberName;
          fm.payAmount.value = formatMoney(mc.payAmount);
          fillData(mc);
        } else {
          window.alert(data.msg);
          clme();
        }
      });
    } else {
      clme();
    }
  }
  function clme() {
    var fm = getEl("fm_input");
    fm.contractCode.value = "";
    fm.saleDate.value = "";
    fm.earnestType.value = "";
    fm.memberCode.value = "";
    fm.memberName.value = "";
    fm.payAmount.value = "";
    clearData();
  }
</script>
        <tr>
          <th width="85">定金编号</th>
          <td width="160"><input type="text" name="contractCode" value="" req="定金编号" onchange="getme(this.value);" maxlength="20"></td>
          <th width="85"></th>
          <td width="160"></td>
        </tr>
        <tr>
          <th>销售日期</th>
          <td><input type="text" name="saleDate" value="" class="date disable" maxlength="10" readonly></td>
          <th>定金类型</th>
          <td><input type="text" name="earnestType" value="" class="disable" readonly></td>
        </tr>
        <tr>
          <th>会员姓名</th>
          <td><input type="text" name="memberName" value=""  class="disable" readonly></td>
          <th>会员编号</th>
          <td><input type="text" name="memberCode" value="" class="disable" readonly></td>
        </tr>
        <tr>
          <th>定金金额</th>
          <td><input type="text" name="payAmount" value="" class="disable" readonly></td>
          <th></th>
          <td></td>
        </tr>

        <tr>
          <th>原付款方式</th>
          <td colspan="3"><select name="payListId" class="w2" req="原付款方式"></select></td>
        </tr>
        <tr>
          <th>新付款方式</th>
          <td colspan="3"><select name="payType" class="w2"><option value=""></option><#if payType??><#list payType as t><option value="${t.id}">${t.id} - ${t.name}</option></#list></#if></select></td>
        </tr>

<script type="text/javascript">
  function fillData(mc) {
    getJson("getPayList?saleId="+mc.saleId+"&saleType=08", function(data){
      if(data.ret) {
        fillPayType(data.data);
      } else {
        window.alert(data.msg);
      }
    });
  }
  function fillPayType(tl) {
    var sl = getEl("fm_input").payListId;
    sl.length = 0;
    for(var i=0; i<tl.length; i++) {
      sl.options.add(new Option(tl[i].payType+' - '+tl[i].payTypeName+'  '+formatMoney(tl[i].amount), tl[i].id));
    }
  }
  function clearData() {
    var fm = getEl("fm_input");
    fm.payListId.length = 0;
  }
</script>

</@add.html>